// 用户相关请求模块

import request from '@/utils/api/request'
// 使用qs：将数据序列化成url格式
import qs from 'qs'

// 新建抽屉
export function create (data) {
  return request({
    method: 'POST',
    url: `/UserLib/userLibrary/lib`,
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 获取文档库
export function getLibrary (data) {
  return request({
    method: 'GET',
    url: `/UserLib/selectlib?uid=${data}`,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}
// 删除文档库
export function deleteLibrary (data) {
  return request({
    method: 'DELETE',
    url: `/UserLib/userLibrary`,
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

// 上传附件
// export function uploadFile (formData, lid) {
//   return request({
//     method: 'POST',
//     url: `/UserLib/userAnnex?lid=${lid}`,
//     data: formData,
//     headers: {
//       'Content-Type': "multipart/form-data"
//     },
//     onUploadProgress: function (event) {
//       const complete = event.loaded / event.total * 100 | 0
//     }
//   })
// }

// 文档库添加文档
export function addArticle (data) {
  return request({
    method: 'POST',
    url: `/UserLib/userDocument`,
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 查看文档库文档
export function showArticle (data) {
  return request({
    method: 'GET',
    url: `/UserLib/userDocuments?lid=${data}`,
  })
}

// 删除文档库文档
export function deleteDoc (id) {
  return request({
    method: 'DELETE',
    url: `/UserLib/deletedoc?id=${id}`,
  })
}

// 查看文档
export function lookDoc (id) {
  return request({
    method: 'POST',
    url: `/UserLib/selectdoc?docid=${id}`,
  })
}

// 编辑文档
export function updateDoc (data, docid) {
  return request({
    method: 'PUT',
    url: `/UserLib/updateDoc?docid=${docid}`,
    data,
    headers: {
      'Content-Type': 'application/json'
    }
  })
}
// 查询全部件
export function showFile (data) {
  return request({
    method: 'GET',
    url: `/UserLib/UserAnnexall?lid=${data}`,
  })
}
// 删除附件
export function deleteFile (id) {
  return request({
    method: 'DELETE',
    url: `/UserLib/Fujain?fujianid=${id}`,
  })
}
// 查看附件
export function lookFile (id) {
  return request({
    method: 'GET',
    url: `/UserLib/UserAnnexone?fujianid=${id}`,
  })
}

// 更新抽屉名称
export function updateLibName (lid, lidname) {
  return request({
    method: 'PUT',
    url: `/UserLib/UserLib?lid=${lid}&lidname=${lidname}`,
  })
}
// 上传图片
export const updatImg = data => {
  return request({
    method: 'POST',
    url: `/aliyun/oss/upfila`,
    data: data
  })
}
